﻿@{
    if (Session["Clinic"] != null)
    {
        HMS.Web.Helpers.Clinic clinic = new HMS.Web.Helpers.Clinic();
        clinic = (HMS.Web.Helpers.Clinic)Session["Clinic"];
        ViewBag.Title = clinic.Name;
    }
    else
    {
        ViewBag.Title = "Index";
    }
}
@model List<HMS.DataContract.Response.DoctorAppointmentResponse>
@*<link href='http://fonts.googleapis.com/css?family=Economica' rel='stylesheet' type='text/css'>*@
<link href="~/Fonts/GoogleFonts.css" rel="stylesheet" type="text/css" />
<link href="~/Content/bootstrap-switch.min.css" rel="stylesheet">
<link href="~/Content/bootstrap-spinner.css" rel="stylesheet">
<link href="~/Content/jquery.bxslider.css" rel="stylesheet" />
<script src="~/Scripts/jquery.bxslider.min.js"></script>

<section class="container">
    <div class="page-heading pull-left col-lg-12 col-md-12 col-xs-12">
        <hr class="pull-left col-lg-12 col-md-12 col-xs-12 clear-padding" />
        @{HMS.DataContract.Response.UserInfo user1 = (HMS.DataContract.Response.UserInfo)Session["userInfo"];
        if (user1 != null && user1.Detail == "P")
        {
            <h1 class="pull-left col-lg-10 col-md-12 col-xs-12 clear-padding">My Profile</h1>
        }
        else
        {
            <h1 class="pull-left col-lg-10 col-md-12 col-xs-12 clear-padding">Search Patient</h1>
        }
        }
        <button id="newAppointment" type="button" class="btn btn-primary">New Appointment</button>
        <hr class="pull-left col-lg-12 col-md-12 col-xs-12 clear-padding" />
    </div>
    @{
        List<HMS.DataContract.Response.DoctorAppointmentResponse> pastAppointments = new List<HMS.DataContract.Response.DoctorAppointmentResponse>();
        List<HMS.DataContract.Response.DoctorAppointmentResponse> futureAppointments = new List<HMS.DataContract.Response.DoctorAppointmentResponse>();
        HMS.DataContract.Response.UserInfo user = (HMS.DataContract.Response.UserInfo)Session["userInfo"];
        string userText = string.Empty;
        if (user != null && user.Detail == "D")
        {
            userText = "Patient";
            <form class="pull-left">
                <div class="form-group">
                    <div id="the-basics" class="input-group">
                        <span class="input-group-addon glyphicon glyphicon-search"></span>
                        <input id="patientSearch" type="text" data-provide="typeahead" class="form-control" placeholder="Name/Phone Number/Email Id" />
                    </div>
                </div>
            </form>
        }
        else
        {
            userText = "You";
        }
    }
    @{
        if (Model != null && Model.Count() != 0)
        {

            <div class="pull-left form">
                <div id="accordion">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Personal details</a>
                            </h4>
                        </div>
                        <div id="collapseOne">
                            <div class="panel-body">
                                <div class="form-group">
                                    <div id="the-basics" class="input-group">
                                        <span class="input-group-addon glyphicon glyphicon-user"></span>
                                        <input id="patientName" type="text" data-provide="typeahead" class="form-control" value="@Model[0].Patient.Name" placeholder="Patient Name" />

                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <span class="input-group-addon glyphicon glyphicon-earphone"></span>
                                        <input id="bookDetailPhone" type="text" class="form-control" placeholder="Cotact Number" value="@Model[0].Patient.Phone">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div id="the-basics" class="input-group">
                                        <span class="input-group-addon">@@</span>
                                        <input id="emailId" type="text" class="form-control" placeholder="Email" value="@Model[0].Patient.Email">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group col-md-2">
                                        <div class="input-group">
                                            <span class="input-group-addon">Age</span>
                                            <input type="text" id="age" class="form-control" disabled placeholder="Age" />
                                            <input type="text" id="dateOfBirth" class="datepicker form-control" placeholder="Select DOB" value="@Model[0].Patient.DOB.ToString("dd'/'MM'/'yyyy")" />
                                            @*<input id="age" type="text" value="0" name="age" class="form-control datepicker">*@
                                        </div>
                                    </div>

                                    <div class="form-group col-md-offset-1 col-md-3">
                                        <div class="input-group input-group-sm">
                                            @{
            if (Model[0].Patient.Gender.Id == 1)
            {
                <input type="checkbox" id="chkGender" data-label-text="Gender" data-on-text="Male" data-off-text="Female" checked class="form-control">
            }
            else
            {
                <input type="checkbox" id="chkGender" data-label-text="Gender" data-on-text="Male" data-off-text="Female" class="form-control">
            }
                                            }

                                        </div>
                                    </div>
                                    @{if (user != null && user.Detail == "D")
                                    {
                                        <div class="form-group col-lg-6 col-md-6">
                                            <div class="input-group col-lg-12 col-md-12">
                                                <span class="input-group-addon"><strong>Access code</strong></span>
                                                <input class="col-lg-6 col-md-6 form-control" disabled="disabled" value="@Model[0].AccessCode" />
                                            </div>
                                        </div>
                                    }
                                    }
                                </div>
                                <button id="savePatientDetails" type="button" class="btn btn-primary pull-right">Save</button>
                            </div>
                        </div>
                    </div>
                </div>
                @{
                                    futureAppointments = Model.Where(x => x.AppointmentDateTime >= DateTime.UtcNow.AddHours(5).AddMinutes(30)).ToList<HMS.DataContract.Response.DoctorAppointmentResponse>();
                                    pastAppointments = Model.Where(x => x.AppointmentDateTime < DateTime.UtcNow.AddHours(5).AddMinutes(30)).ToList<HMS.DataContract.Response.DoctorAppointmentResponse>();

                }
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" class="collapsed">Visit details</a>
                        </h4>
                    </div>

                    <div id="collapseTwo" class="">
                        <div class="panel-body">
                            @{

            if (futureAppointments.Count() > 0)
            {
                <div>
                    <div><strong>Future appointments</strong></div>
                    foreach (var item in futureAppointments)
                    {

                    <span>@userText have an appointment with <strong>@item.DoctorName</strong> at <strong>@item.AppointmentDateTime.ToString("dd-MMM-yyyy hh:mm tt")</strong></span><br />
                    <div class="form-group">
                        <ul class="bxslider" id="@item.Id"></ul>
                    </div>
                    <div class="divSpace"></div>
                    <div id="divPrescription_@item.Id" class="form-group col-lg-12">

                    </div>
                    }
                    }
                </div>
                            }
                            @{
            if (pastAppointments.Count() > 0)
            {
                <div><strong>Past appointments</strong></div>
                foreach (var item in pastAppointments)
                {
                    <span>@userText had an appointment with <strong>@item.DoctorName</strong> at <strong>@item.AppointmentDateTime.ToString("dd-MMM-yyyy hh:mm tt")</strong></span><br />
                                <div class="form-group">
                                    <ul class="bxslider" id="@item.Id"></ul>
                                </div>
                                <div class="divSpace"></div>
                                <div id="divPrescription_@item.Id" class="form-group col-lg-12">

                                </div>
                }
            }
                            }

                        </div>
                    </div>
                </div>

                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" class="collapsed">Patient Data</a>
                        </h4>
                    </div>

                    <div id="collapseThree" class="">
                        <div class="panel-body">
                            <div class="form-group">
                                <div class="input-group pull-left">
                                    <button type="button" id="btnAddImages" class="btn btn-primary pull-right">Add Images</button>
                                </div>

                                @using (Html.BeginForm("UploadImage", "Appointment", FormMethod.Post, new { EncType = "multipart/form-data", @class = "pull-right" }))
                                {
                                    <input type="file" class="btn btn-primary" onchange="submit()" name='files' title="Browse" multiple id="upload" />
                                    <input type="hidden" name="currentPage" value="Patient/Index" />
                                }
                            </div>
                            <div class="divSpace"></div>
                            <div class="form-group">
                                <ul class="bxslider" id="@Model[0].Patient.Id"></ul>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        }
    }
</section>
<script src="~/Scripts/bootstrap-typeahead.js" type="text/javascript"></script>
<script src="~/Scripts/bootstrap-switch.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.spinner.js" type="text/javascript"></script>
<script src="~/Scripts/bootstrap-combobox.js" type="text/javascript"></script>
<script src="~/Scripts/bootstrap.file-input.js" type="text/javascript"></script>
@{

    if (Session["PatientId"] != null)
    {

        <script src="~/Scripts/jquery.mousewheel-3.0.6.pack.js" type="text/javascript"></script>
        <link href="~/Content/jquery.fancybox.css" rel="stylesheet" type="text/css" media="screen" />
        <script src="~/Scripts/jquery.fancybox.pack.js" type="text/javascript"></script>
        <link href="~/Content/jquery.fancybox-buttons.css" rel="stylesheet" type="text/css" />
        <link href="~/Content/jquery.fancybox-thumbs.css" rel="stylesheet" type="text/css" />
        <script src="~/Scripts/jquery.fancybox-buttons.js" type="text/javascript"></script>
        <script src="~/Scripts/jquery.fancybox-media.js" type="text/javascript"></script>
        <script src="~/Scripts/jquery.fancybox-thumbs.js" type="text/javascript"></script>
        <script type="text/javascript">
            var prevAppt = JSON.parse('@Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(pastAppointments))')
            var futureAppt = JSON.parse('@Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(futureAppointments))')
            var patientId = '@Model[0].Patient.Id';
            $("#patientSearch").val('@Model[0].Patient.Name');
        </script>
        <script src="~/Scripts/ViewScripts/Patient/index.js" type="text/javascript"></script>
    }


    <script type="text/javascript">
        $('#patientSearch').typeahead({
            source: function (query, process) {
                var $items = new Array;
                $items = [""];
                $.ajax({
                    type: "POST",
                    url: _AbsolutePath + 'Patient/GetPatientName',
                    contentType: "application/json",
                    data: JSON.stringify({ PatientName: query }),
                    dataType: "json",
                    success: function (data) {
                        $.map(data, function (data) {
                            var group;
                            group = {
                                id: data.Id,
                                name: data.Name + " ( " + data.Phone + ", " + data.Email + " ) ",
                                toString: function () {
                                    return JSON.stringify(this);
                                    //return this.app;
                                },
                                toLowerCase: function () {
                                    return this.name.toLowerCase();
                                },
                                indexOf: function (string) {
                                    return String.prototype.indexOf.apply(this.name, arguments);
                                },
                                replace: function (string) {
                                    var value = '';
                                    value += this.name;
                                    if (typeof (this.level) != 'undefined') {
                                        value += ' <span class="pull-right muted">';
                                        value += this.level;
                                        value += '</span>';
                                    }
                                    return value;
                                }
                            };
                            $items.push(group);
                        });

                        process($items);
                    }
                });
            },
            property: 'name',
            items: 10,
            minLength: 1,
            updater: function (item) {
                var item = JSON.parse(item);
                console.log(item.name);
                $('#SelectedPatient').val(item.id);
                SetPatientSession(item.id, item.name);
                return item.name;
            }
        });


        function SetPatientSession(PatId, PatName) {
            $.ajax({
                async: true,
                type: "POST",
                url: _AbsolutePath + 'Patient/SetPatientSession',
                contentType: "application/json",
                data: JSON.stringify({ PatientId: PatId, PatientName: PatName }),
                caller: arguments.callee.name,//gets currently running function name
                dataType: "json", //Cross domain call (even json also work)
                success: function (res) {
                    location.href = "/Patient/Index";
                },
                error: function (xhr) {
                }
            });
        }
    </script>

}